<form id="frm_role_edit" method="POST" action="<?php echo $save_action; ?>">
    <?php $this->load->view('site/role/message'); ?>
    <input id="entity_id" type="hidden" name="id" value="<?php echo $role->id; ?>" />
    <div class="clearfix auto_height mb_10">
        <?php $this->load->view('admin/site/role/buttons'); ?>
    </div>
    <div class="form_block">
        <div class="block_header">
            Thông tin căn bản
        </div>
        <div class="block_content">
            <table cellpadding="0px" cellspacing="0px">
                <tr>
                    <td class="frm_label">Tên chức vụ(*)</td>
                    <td class="frm_field">
                        <input placeholder="Tên chức vụ" type="text" class="std_input required" name="data[name]" value="<?php echo $role->name; ?>" />
                    </td>
                </tr>
                <tr>
                    <td class="frm_label">Mô tả</td>
                    <td class="frm_field">
                        <textarea placeholder="Mô tả chức vụ" name="data[description]"><?php echo $role->description; ?></textarea>
                    </td>
                </tr>
                <tr>
                    <td class="frm_label">Là chức vụ hệ thống(*)</td>
                    <td class="frm_field">
                        <label>
                            <input <?php if ($role->is_system == 1) :?>checked="checked"<?php endif; ?> type="checkbox" class="std_chk" name="data[is_system]" />
                            <span>Có / Không</span>
                        </label>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <?php if (count($privileges) > 0 && $privileges) :?>
    <div class="form_block" style="margin-bottom: 0px; padding-bottom: 0px;">
        <div class="block_header">
            Gán quyền hạn
        </div>
    </div>
    <table class="gridview" width="100%" cellpadding="0" cellspacing="0" style="margin-bottom: 10px;">
        <thead>
        <tr>
            <td><input type="checkbox" onclick="btn_util.check_all(this.checked, '.chk')" /></td>
            <td><b>ID</b></td>
            <td><b>Tên</b></td>
            <td><b>Mô tả</b></td>
            <td><b>Quyền</b></td>
            <td><b>Thao tác</b></td>
        </tr>
        </thead>
        <tbody>
        <?php foreach ($privileges as $privilege) : ?>
        <tr>
            <input type="hidden" value="" class="edit_url" />
            <td width="30px" valign="top">
                <input <?php if (in_array($privilege->id, $role->privileges)) :?>checked="checked"<?php endif; ?> name="data[privileges][]" type="checkbox" value="<?php echo $privilege->id; ?>" class="chk" />
            </td>
            <td width="30px" valign="top">
                <?php echo $privilege->id; ?>
            </td>
            <td valign="top">
                <?php echo $privilege->name; ?>
            </td>
            <td valign="top">
                <?php echo $privilege->description; ?>
            </td>
            <td valign="top">
                <?php echo $privilege->url; ?>
            </td>
            <td valign="top">
                <p><a class="icon icon_edit" target="_blank" href="<?php echo site_url('admin/site/privilege/id/' . $privilege->id, true); ?>"></a> <a class="icon icon_delete" href="<?php echo site_url('admin/site/privilege/delete/id/' . $privilege->id, true); ?>" target="_blank" onclick="return confirm('Bạn muốn xóa quyền hạn này?')"></a></p>
            </td>
        </tr>
            <?php endforeach; ?>
        </tbody>
        <tfoot>

        </tfoot>
    </table>
    <?php endif; ?>
    <div class="form_block" style="margin-bottom: 0px; padding-bottom: 0px;">
        <div class="block_header">
            <div class="bl">Quyền hệ thống</div> <div class="bl ml_10"><label><input onclick="btn_util.check_all(this.checked, '.chk_privilege');" type="checkbox" class="std_chk" /> <span>Chọn hết / Bỏ chọn hết</span></label></div>
        </div>
    </div>
    <div class="lst_group">
        <?php $index = 1; foreach ($system_privileges as $group_privilege) :?>
        <div class="db_side_block">
            <div class="db_side_header">
                <label>
                    <input class="std_chk chk_privilege" type="checkbox" onclick="btn_util.check_all(this.checked, '.chk_<?php echo $index; ?>')" />
                    <strong>#<?php echo $index; ?>. <?php echo $group_privilege['name']; ?></strong>
                </label>
            </div>
            <div class="db_inner_content">
                <ul>
                    <?php $system_index = 1; foreach ($group_privilege['children'] as $system_privilege) :?>
                    <li>
                        <label>
                            <input <?php if (in_array($system_privilege['alias'], $role->system_privileges)) :?>checked="checked"<?php endif; ?> name="data[system_privileges][]" class="std_chk chk_privilege chk_<?php echo $index; ?>" type="checkbox" value="<?php echo $system_privilege['alias']; ?>" />
                            <span class="icon icon_privilege"></span>
                            <strong>[#<?php echo $system_index; ?>]. <?php echo $system_privilege['name']; ?></strong>
                        </label>
                    </li>
                    <?php $system_index++; ?>
                    <?php endforeach; ?>
                </ul>
            </div>
        </div>
        <?php $index++; ?>
        <?php endforeach; ?>
        <div class="clearfix"></div>
    </div>
</form>